sprite = codesters.Sprite("person1")
# question
answer = sprite.ask("Did you do your homework?")
answer = answer.lower()
# check what answer is equal to
if answer == "yes":
# if answer is yes, do this
sprite.go_to(-3, -5)
sprite.say("Cool, I can go to the beach!")
# check what answer is equal to
if answer == "no":
# if answer is no, then do this
sprite.go_to(3, -5)
sprite.say("I better stay home then.")
stage.set_axis(250)
stage.wait(3)
sprite.say(' ')
question1 = MCQ(1,"","","","","","", "row")
question1.set_prompt(" 1) Which of the following is a test variable?")
question1.set_choice_A('"if answer == "yes":')
question1.set_choice_B('"no"')
question1.set_choice_C('choice')
question1.set_choice_D('"yes"')
question1.set_correct("C")
question2 = MCQ(2,"","","","","","", "row")
question2.set_prompt("2) Which line is indented in the editor?")
question2.set_choice_A('"if answer == "yes":')
question2.set_choice_B('sprite.say("I better stay home then.")')
question2.set_choice_C('if answer == "no":')
question2.set_choice_D('answer = "yes"')
question2.set_correct("B")
question3 = MCQ(3,"","","","","","", "row")
question3.set_prompt('3) What will happen if the answer is "yes"?')
question3.set_choice_A('The sprite will say, "Cool, I can go to the beach!"')
question3.set_choice_B('The sprite will say, "I better stay home then."')
question3.set_choice_C('The sprite will say both lines at the same time.')
question3.set_choice_D('The sprite will say the beach line then the home line.')
question3.set_correct("A")
repeat_test = True
stop_test = False
def test_script():
global repeat_test
global stop_test
try:
tval1 = question1.correct
except:
tval1 = "DNE"
try:
tval2 = question2.correct
except:
tval2 = "DNE"
try:
tval3 = question3.correct
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == True, " ")
t1.add_failure(tval1 == False, "Q1 wrong")
t1.add_failure(tval1 == "DNE", " ")
t2 = TestObjective()
t2.add_success(tval2 == True, " ")
t2.add_failure(tval2 == False, "Q2 wrong")
t2.add_failure(tval2 == "DNE", " ")
t3 = TestObjective()
t3.add_success(tval3 == True, " ")
t3.add_failure(tval3 == False, "Q3 wrong")
t3.add_failure(tval3 == "DNE", " ")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
#tester.display_first_feedback()
if repeat_test == False:
stop_test = True
test_counter = 0
def repeat_tests():
global stop_test
global test_counter
if stop_test == False:
test_script()
if test_counter >= 100:
stop_test = True
stage.event_interval(repeat_tests, .2)